package adminlte.vo;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Data;
import org.springframework.http.HttpStatus;

/**
 * 下面的字段为dataTables.js通过ajax调用所需的返回数据
 * data字段继承自responseData也是dataTables所需字段，里面为待渲染数据
 * @author ZHUFEIFEI
 */
@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseTableData<T> extends ResponseData<T> {

    /**
     *调用次数, 可选，如果有返回的值但是不变会导致前端加载无法结束
     */
    private Integer draw;
    /**
     * 记录总数
     */
    private int recordsTotal;
    /**
     * 过滤后的记录总数
     */
    private int recordsFiltered;

    public ResponseTableData(HttpStatus status) {
        super(status);
    }

    public static <T> ResponseTableData<T> ok(int recordsTotal, int recordsFiltered, T data) {
        return ok(null, recordsTotal, recordsFiltered, data);
    }

    public static <T> ResponseTableData<T> ok(Integer draw, int recordsTotal, int recordsFiltered, T data) {
        ResponseTableData tableData = new ResponseTableData<>(HttpStatus.OK);
        tableData.setDraw(draw);
        tableData.setRecordsTotal(recordsTotal);
        tableData.setRecordsFiltered(recordsFiltered);
        tableData.setData(data);
        return tableData;
    }

}
